package com.zhouheng.springbootmultithreading.module.task;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;


/**
 * 配置定时任务类
 *
 * @author 周恒
 * @date 20190509 15:05:09
 * @since v1.0
 */
@Configuration
public class ScheduleConfig {

    /**
     * 主线程池
     *
     * @return 返回 thread pool task scheduler 描述此返回参数
     * @author LeoRmAo
     * @date 20190905 11:00:05
     * @since v1.0
     */
    @Bean
    @ConditionalOnMissingBean(ThreadPoolTaskScheduler.class)
    public ThreadPoolTaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        //设置线程池大小
        taskScheduler.setAwaitTerminationSeconds(60);
        taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
        taskScheduler.setPoolSize(20);
        taskScheduler.setThreadNamePrefix("task-");
        return taskScheduler;
    }

}
